package pucp.carpooling.adapter;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import pucp.carpooling.R;

public class ListViewAdapterConductor extends BaseAdapter {

	// Declare Variables
	Context context;
	Date d;
	String[] conductor, destino, fecha, libres, precio;
	int[] flag;
	LayoutInflater inflater;

	public ListViewAdapterConductor(Context context, String[] conductor, String[] destino,
			String[] fecha, String[] libres, String[]precio, int[] flag) {
		this.context = context;
		this.conductor = conductor;
		this.destino = destino;
		this.fecha = fecha;
		this.flag = flag;
		this.libres=libres;
		this.precio=precio;
	}

	public int getCount() {
		return conductor.length;
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		// Declare Variables
		TextView txtconductor, txtdestino, txtfecha , txtPrecio, txtLibres;
		
		ImageView imgflag;

		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View itemView = inflater.inflate(R.layout.listview_item_avisos_conductor, parent, false);

		
		txtconductor = (TextView) itemView.findViewById(R.id.txtConductor);
		txtdestino = (TextView) itemView.findViewById(R.id.txtDestinoConductor);
		txtfecha = (TextView) itemView.findViewById(R.id.txtFecha);
		txtPrecio = (TextView) itemView.findViewById(R.id.txtPrecio);

		txtLibres = (TextView) itemView.findViewById(R.id.txtLibres);
		imgflag = (ImageView) itemView.findViewById(R.id.flagconductor);

		
		txtconductor.setText(conductor[position]);
		txtdestino.setText(destino[position]);
		
		
		SimpleDateFormat formatoIn = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		SimpleDateFormat formatoOutFecha = new SimpleDateFormat("dd-MM-yyyy  HH:mm");
		//SimpleDateFormat formatoOutHora = new SimpleDateFormat("HH:mm");
		String fechita = fecha[position];
		
		try {
			d = (Date) formatoIn.parse(fechita);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
			
		txtfecha.setText(formatoOutFecha.format(d));
		txtPrecio.setText(precio[position]);
		txtLibres.setText(libres[position]);

		
		imgflag.setImageResource(flag[position]);

		return itemView;
	}
}
